<?php

class SysDataBehavior extends CActiveRecordBehavior {

	public $beforeSaveAllow = true;
	public $beforeDeleteAllow = true;
	public $sys = array();
	
	public function beforeSave($event) {
		$owner = $this->owner;
		if ($this->beforeSaveAllow) return true;
		foreach ($owner->attributes as $key => $val) {
			if (array_key_exists($key, $this->sys)) {
				if (in_array($val, $this->sys[$key])) {
					Yii::app()->user->setFlash(FLASH::RESULT_WARNING,'系统数据不能修改');
					$event->isValid = false;
					break;
				}
			}
		}
	}

	public function beforeDelete($event) {
		$owner = $this->owner;
		if ($this->beforeDeleteAllow) return true;
		foreach ($owner->attributes as $key => $val) {
			if (array_key_exists($key, $this->sys)) {
				if (in_array($val, $this->sys[$key])) {
					Yii::app()->user->setFlash(FLASH::RESULT_WARNING,'系统数据不能删除');
					$event->isValid = false;
					break;
				}
			}
		}
	}
}

?>